<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="${articleDetail.description}">
    <meta name="keywords" content="${articleDetail.findKeywords()}">
    <meta name="author" content="燕归来兮">
    <title>${articleDetail.title}-燕归来兮</title>
    <#include "../common/link.ftl"/>
    <link rel="stylesheet" href="/editor.md/css/editormd.preview.css"/>
    <style>
        .articleCard {
            margin-left: 20px;
        }

        #articleDetail {
            padding: 20px;
        }

        .columns {
            padding: 10px 20px 10px 20px;
        }

        a.tag {
            text-decoration: none !important;
        }

        @media screen and (max-width: 768px) {
            .content {
                width: 100%;
            }

            .columns {
                padding: 10px 0 10px 0;
            }
        }


        @media screen and (min-width: 768px) {
            .content {
                width: 80%;
            }

            .columns {
                padding: 10px 20px 10px 20px;
            }
        }
    </style>
</head>
<body>

<section class="hero is_blue is-medium">
    <div class="hero-head">
        <#include "../common/nav.ftl"/>
    </div>
    <div class="hero-body">
        <div class="container has-text-centered">
            <p class="title is-size-1 mb-6">
                ${articleDetail.title}
            </p>
            <#--            <p class="subtitle">-->
            <#--                凡心之所向,素履以往,生如逆旅,一苇以航-->
            <#--            </p>-->
        </div>
    </div>

    <!-- Hero footer: will stick at the bottom -->
    <div class="hero-foot">
    </div>
</section>


<#-- 文章列表 -->
<div class="is-flex is-justify-content-center mt-4">
    <div class="columns content">
        <div class="column is-four-fifths">
            <div class="columns" style="display: flex;flex-wrap: wrap;">
                <div>
                    <a class="tag is-info is-light is-medium mb-1 mr-1">
                        <i class="fa fa-clock-o"></i>
                        ${articleDetail.createdAt}
                    </a>
                </div>

                <a class="tag is-warning is-light is-medium mb-1 mr-1">
                    <i class="fa fa-book"></i>
                    阅读数: ${articleDetail.readCount}
                </a>

                <a class="tag is-success is-light is-medium mb-1 mr-1">
                    <i class="fa fa-comment"></i>
                    评论数: ${articleDetail.commentCount}
                </a>

                <a class="tag is-warning is-light is-medium mb-1 mr-1"
                   href="/blog?category=${articleDetail.categoryTitle}">
                    <i class="fa fa-folder-open-o"></i>
                    ${articleDetail.categoryTitle}
                </a>


                <#list articleDetail.tags as tag>
                    <a class="tag is-link is-light is-medium mb-1 mr-1" href="/blog?tag=${tag}">
                        <i class="fa fa fa-tag"></i>
                        ${tag}
                    </a>
                </#list>
            </div>


            <div style="margin: 20px 0 20px 0;">
                <a class="markdown-body editormd-preview-container">
                    <div id="toc-container">暂无目录</div>
                </a>
            </div>

            <div id="articleDetail" class="box">

                <div id="editorMd">
                    <textarea id="append-test" style="display:none;">${articleDetail.mkContent}</textarea>
                </div>
            </div>


            <div id="articleCommentList" class="box">
                <#-- 回复列表 -->
                <#list comments as comment>
                    <article class="media">
                        <figure class="media-left is-hidden-mobile">
                            <p class="image is-64x64">
                                <img src="https://bulma.io/images/placeholders/128x128.png">
                            </p>
                        </figure>
                        <div class="media-content">
                            <#--评论内容-->
                            <div class="content">
                                <p>
                                    <strong>${comment.nickname}</strong>
                                    <br>
                                    ${comment.content}
                                    <br>
                                    <small>
                                        <#--                                        <a>Like</a> · <a>Reply</a> -->
                                        评论时间 · ${comment.createdAt}</small>
                                </p>
                            </div>

                            <#if comment.replyComment?size &gt; 0>
                                <#list comment.replyComment as replyComment>
                                <#-- 评论回复列表 -->
                                    <article class="media">
                                        <figure class="media-left is-hidden-mobile">
                                            <p class="image is-48x48">
                                                <img src="https://bulma.io/images/placeholders/96x96.png">
                                            </p>
                                        </figure>
                                        <div class="media-content">
                                            <div class="content">
                                                <p>
                                                    <strong>${replyComment.nickname}</strong>
                                                    <br>
                                                    ${replyComment.content}
                                                    <br>
                                                    <small>
                                                        <#--                                                        <a>Like</a> · <a>Reply</a> -->

                                                        评论时间 · ${replyComment.createdAt}
                                                    </small>
                                                </p>
                                            </div>
                                        </div>
                                    </article>

                                </#list>
                            </#if>

                        </div>
                    </article>
                </#list>
            </div>


            <div id="articleComment" class="box">
                <div id="commentInfo">

                </div>

                <div id="content">
                    <div class="field is-horizontal">
                        <div class="field-body">
                            <div class="field">
                                <p class="control is-expanded has-icons-left">
                                    <input id="nicknameInput" class="input" type="text" placeholder="请输入您的昵称">
                                    <span class="icon is-small is-left"><i class="fas fa-user"></i></span>
                                </p>
                            </div>
                            <div class="field">
                                <p class="control is-expanded has-icons-left has-icons-right">
                                    <input id="emailInput" class="input is-success" type="email" placeholder="请输入您的邮箱">
                                    <span class="icon is-small is-left"><i class="fas fa-envelope"></i></span>
                                </p>
                            </div>
                        </div>
                    </div>

                    <div class="field is-horizontal">

                        <div class="field-body">
                            <div class="field is-expanded">
                                <div class="field has-addons">
                                    <p class="control is-expanded">
                                        <label><textarea id="contentInput" class="textarea" type="tel"
                                                         placeholder="请输入评论内容"></textarea>
                                        </label>
                                    </p>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="field is-horizontal">
                        <div class="field-body">
                            <div class="field">

                                <button class="button is-primary" onclick="addComment()">
                                    直接提交
                                </button>

                                <button class="button is-info">
                                    保存为草稿
                                </button>

                            </div>
                        </div>
                    </div>

                </div>

            </div>
        </div>
        <div class="column is-hidden-mobile">
            <#include "../blog/tags-recommend.ftl"/>
            <#include "../blog/category-recommend.ftl"/>
            <#include "../blog/github-recommend.ftl"/>
        </div>
    </div>
</div>

<#-- 尾部 -->
<#include "../common/footer.ftl"/>
<script src="/editor.md/lib/jquery.min.js"></script>
<script src="/editor.md/editormd.min.js"></script>
<script src="/editor.md/lib/marked.min.js"></script>
<script src="/editor.md/lib/prettify.min.js"></script>
<script src="/editor.md/lib/raphael.min.js"></script>
<script src="/editor.md/lib/underscore.min.js"></script>
<script src="/editor.md/lib/sequence-diagram.min.js"></script>
<script src="/editor.md/lib/flowchart.min.js"></script>
<script src="/editor.md/lib/jquery.flowchart.min.js"></script>

<script src="/editor.md/editormd.js"></script>


<script src="/layuimini/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script type="text/javascript">
    let testEditor;
    $(function () {
        testEditor = editormd.markdownToHTML("editorMd", {
            path: "/editor.md/lib/",
            htmlDecode: "style,script,iframe",  // you can filter tags decode
            emoji: false,
            taskList: true,
            tex: true,  // 默认不解析
            flowChart: true,  // 默认不解析
            sequenceDiagram: true,  // 默认不解析
            tocContainer: "#toc-container",
            tocDropdown: false
        });
    });


    function addComment() {
        let nickname = $("#nicknameInput").val()
        let email = $("#emailInput").val()
        let content = $("#contentInput").val()
        let refId = ${articleDetail.id};
        if (nickname.trim() === '' || content.trim() === '') {
            alert("昵称或者评论内容不能为空")
            return
        }
        let commentRequest = {
            refId: refId,
            parentId: 0,
            nickname: nickname,
            email: email,
            content: content
        }
        $.ajax({
            type: 'POST',
            url: '/api/comment',
            data: JSON.stringify(commentRequest),
            dataType: "json",
            contentType: 'application/json',
            success: function (res) {
                let {code, msg} = res
                if (code === 0) {
                    alert("新增评论完成")
                    location.reload();
                } else {
                    alert(msg)
                }
            }
        })
    }
</script>
</body>
</html>
